<?php
  include_once dirname(__FILE__)."/../classes/collection.class.php";
  include_once dirname(__FILE__)."/../classes/card.class.php";

  class Deck extends Collection
  {
    public function Deck($id)
    {
      parent::__construct($id);
    }

    public function getCards($order = array(), $limit = array('page' => 0, 'pagelimit' => 10000000))
    {
      global $db;

      $return_cards = array();

      $order = array_merge(array(array('column' => "`Expansion`.`release_date`", 'direction' => "DESC")),$order);

      $cards = $db->getCardsInDeck($this->id, $order, $limit);

      foreach($cards as $card)
      {
        array_push($return_cards, new Card($card->ID));
      }

      return $return_cards;
    }

    public function shuffleDeck()
    {
      $cards = $this->getCards(array(),array());
      $deck = array();
      $returnDeck = array();
      foreach($cards as $card)
      {
        $amount = $this->getAmount($card->cardid);
        $amount = $amount[0] + $amount[1];
        for($a = 0 ; $a < $amount ; $a++)
        {
          array_push($deck, $card);
        }
      }

      $b=0;
      do
      {
        for($a = 0 ; $a < count($deck) ; $a++)
        {
          $tempcard = $deck[$a];
          $newLocation = rand(0,count($deck)-1);
          $deck[$a] = $deck[$newLocation];
          $deck[$newLocation] = $tempcard;
        }
        $b++;
      }
      while($b < 10);
      
      return $deck;
    }
  }
?>
